<?php
namespace app\admin\controller;

use app\admin\event\Utils;
use think\facade\Request;

class Example extends Base
{
    public function form()
    {
        if(Request::isPost()){
            $params = Request::param();
            $res = ['success'=>0,'msg'=>'测试表单提交完成，提交内容：'.json_encode($params)];
            Utils::ifrResponse($res);
        }

        $field = [
            ['label'=>'','name'=>'id','type'=>'hidden'],
            ['label'=>'select2选择框','name'=>'select2','type'=>'select2','options'=>['选项一','选项二','选项三']],
            ['label'=>'普通input','name'=>'input'],
            ['label'=>'不可输入input','name'=>'input2','disabled'=>true],
            ['label'=>'必填input','name'=>'input3','required'=>true,'tips'=>'这是一个必填input，请不填写试试'],
            ['label'=>'图标','name'=>'icon','type'=>'icon','tips'=>''],
            ['label'=>'select2选择框多选','name'=>'select2_multiple','type'=>'select2','options'=>['多选项一','多选项二','多选项三'],'multiple'=>true],
            ['label'=>'数字输入','name'=>'number','type'=>'number','tips'=>'这里是提示输入'],
            ['label'=>'图片上传','name'=>'img','type'=>'img','tips'=>''],
            ['label'=>'普通select','name'=>'select','type'=>'select','tips'=>'原生select下拉选择','options'=>['选项一','选项二','选项三']],
            ['label'=>'radio','name'=>'radio','type'=>'radio','options'=>['单选项一','单选项二','单选项三']],
            ['label'=>'checkbox','name'=>'checkbox','type'=>'checkbox','options'=>['单选项一','单选项二','单选项三']],
            ['label'=>'随机数生成','name'=>'random_str','type'=>'random_str','length'=>20],
            ['label'=>'文本输入框','name'=>'textarea','type'=>'textarea','length'=>20,'tips'=>'可以通过`length`来限制最大输入字符']
        ];
        $defaultData = [
            'id' => 1,
            'select2' => 1,
            'input' => '这是input的默认值',
            'input2' => '这是一个不可输入的input框',
            'icon' => 'fa-home',
            'select2_multiple' => '1,2',
            'checkbox' => '1,2',
            'radio' => 2,
            'select' => 2
        ];
        return $this->_buildEditForm('表单示例（快速生成提交表单）',$field,$defaultData,url('form'));
    }
}